local DropManager = class("DropManager")
local TypeConst = require("const.TypeConst")
local type_manage = require("config.type_manage")

function DropManager:ctor()
end

function DropManager:monsterDrop(monsterId)
    local monsteam = require("config.monster_team").get(monsterId)
    assert(monsteam, "can not found cfg in monster_team bg id=" .. monsterId)
    local dropId = monsteam.drop_id
    local drop = require("config.drop").get(dropId)
    assert(drop, "can not found cfg in drop by id=" .. dropId)
    local result = {}
    for i = 1, 4 do
        local randNum = math.random(1, 1000)
        local randNum = randNum / 10
        if randNum <= drop["pro_" .. i] then
            local param = {}
            param.type = drop["type_" .. i]
            param.value = drop["value_" .. i]
            param.size = drop["size_" .. i]
            table.insert(result, param)
        end
    end
    self:dispatchDrop(result)
    return result
end

function DropManager:drop(award)
    local result = {}
    table.insert(result, award)
    self:dispatchDrop(result)
end

function DropManager:dispatchDrop(result)
    for i = 1, #result do
        local param = result[i]
        local name = type_manage.get(param.type)
        local dropFunc = self["_type_" .. name.name .. "_drop"]
        if dropFunc then
            dropFunc(self, param)
        end
    end
end

function DropManager:_type_items_drop(drop)
    G_UserData:getItems():addData(drop.value, drop.size, true)
end

function DropManager:_type_equipment_drop(drop)
    local size = drop.size
    for i = 1, size do
        G_UserData:getEquipment():addData(drop.value)
    end
end

function DropManager:_type_magickey_drop(drop)
    local size = drop.size
    for i = 1, size do
        G_UserData:getMagickey():addData(drop.value)
    end
end

function DropManager:_type_gemstone_drop(drop)
    local size = drop.size
    for i = 1, size do
        G_UserData:getGemstone():addData(drop.value)
    end
end

function DropManager:_type_resource_drop(drop)
    G_UserData:getResource():addData(drop.value, drop.size, true)
end

function DropManager:_type_hero_drop(drop)
    local size = drop.size
    for i = 1, size do
        G_UserData:getHero():addData(drop.value)
    end
end

return DropManager
